<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../common/jquery/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../common/bootstrap/bootstrap-4.4.0-dist/js/bootstrap.js"></script>
<link href="../css/basic_layout.css" rel="stylesheet" type="text/css">
<link href="../css/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/commonAll.js"></script>
<script type="text/javascript" src="../js/artDialog.js"></script>
<title>信息管理系统</title>
<style>
	.alt td{ background:black !important;}
	.add{
		color: blue;
	}
</style>
</head>
<body>
	<form id="submitForm" name="submitForm" action="" method="post">
		<input type="hidden" name="allIDCheck" value="" id="allIDCheck"/>
		<input type="hidden" name="fangyuanEntity.fyXqName" value="" id="fyXqName"/>
		<div id="container">
			<a href='#' class="add" onclick='add(this);return false;'>论文题目发布</a>
			<div class="ui_content">
				<div class="ui_text_indent">
					<div id="box_border">
					</div>
				</div>
			</div>
			<div class="ui_content">
				<div class="ui_tb">
					<table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
						<thead>
							<tr>
								<th>论文题目</th>
								<th>论文描述</th>
								<th>当前状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="Tbody">
							
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</form>
</body>
<script type="text/javascript">
var list;
$(document).ready(function(){
	$.ajax({
		url:"selectallsbj",
		success:function(result){
			$("#Tbody").empty();
			list = result;
	        for(var i=0;i<result.length;i++){
	        	var $trTemp = $("<tr></tr>");
	        	$trTemp.append("<th>"+ result[i].sbj_name +"</th>");
	            $trTemp.append("<th>"+ result[i].sbj_describe +"</th>");
	            $trTemp.append("<th>"+ result[i].sbj_status +"</th>");
	            if(result[i].sbj_status == "暂时保存"){
	            	$trTemp.append("<th>"+ 	"<a href='#' onclick='edit(this);return false;'>编辑</a>"+ " " + 
	            							"<a href='#' onclick='submit(this);return false;'>提交</a>"+ " " + 
	            							"<a href='#' onclick='del(this);return false;'>删除</a>"+"</th>");
	            }
	            else if(result[i].sbj_status == "审核未通过"){
	            	$trTemp.append("<th>"+ 	"<a href='#' onclick='edit(this);return false;'>编辑</a>"+ " " + 
											"<a href='#' onclick='del(this);return false;'>删除</a>"+"</th>");
	            }
	            else{
	            	$trTemp.append("<th>"+ "<a href='#' onclick='view(this);return false;'>查看</a>"+"</th>");
	            }
	            $trTemp.appendTo("#Tbody");
        	}
		},
		error: function(err){
			console.log(err);
		}
    });
})

function add(){
	sessionStorage.setItem("action", "add");
	window.location.href = "./LunWenInfo";
}

function edit(curE){
	var tr = curE.parentNode.parentNode;
	var children = tr.childNodes;
	var index = tr.rowIndex - 1;
	sessionStorage.setItem("action", "edit");
	sessionStorage.setItem("sbj_id", list[index].sbj_id);
	sessionStorage.setItem("sbj_name", children[0].innerText);
	sessionStorage.setItem("sbj_describe", children[1].innerText);
	sessionStorage.setItem("sbj_status", children[2].innerText);
	window.location.href = "./LunWenInfo";
}

function view(curE){
	var tr = curE.parentNode.parentNode;
	var children = tr.childNodes;
	var index = tr.rowIndex - 1;
	sessionStorage.setItem("action", "view");
	sessionStorage.setItem("sbj_id", list[index].sbj_id);
	sessionStorage.setItem("sbj_name", children[0].innerText);
	sessionStorage.setItem("sbj_describe", children[1].innerText);
	sessionStorage.setItem("sbj_status", children[2].innerText);
	window.location.href = "./LunWenInfo";
}

function submit(curE){
	var tr = curE.parentNode.parentNode;
	var index = tr.rowIndex - 1;
	var children = tr.childNodes;
	sessionStorage.setItem("action", "view");
	sessionStorage.setItem("sbj_name", children[0].innerText);
	sessionStorage.setItem("sbj_describe", children[1].innerText);
	sessionStorage.setItem("sbj_status", children[2].innerText);
	var data = {
			sbj_id: list[index].sbj_id,
			sbj_name: list[index].sbj_name,
			sbj_describe: list[index].sbj_describe,
			sbj_status: "ct02"
	};
	$.ajax({
		url: "updatesbj",
		method: "post",
		data: data,
		dataType: "json",
		success: function(res){
			alert("提交成功！");
			history.go(0);
		},
		error: function(err){
			alert("提交失败！");
		}
	})
}

function del(curE){
	var tr = curE.parentNode.parentNode;
	var index = tr.rowIndex - 1;
	var data = {
			sbj_id: list[index].sbj_id
	};
	$.ajax({
		url: "deletesbj",
		method: "post",
		data: data,
		dataType: "json",
		success: function(res){
			alert("删除成功！");
			history.go(0);
		},
		error: function(err){
			alert("删除失败！");
		}
	})
}
</script>
</html>
